import 'dart:io';

import 'package:android_id/android_id.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:my_flutter_core/models/device_info.dart';

/// Gets current device unique id.
Future<String?> getDeviceId() async {
  return const AndroidId().getId();
}

/// Gets current device info.
Future<DeviceInfo?> getDeviceInfo() async {
  final deviceInfoPlugin = DeviceInfoPlugin();
  DeviceInfo? deviceInfo;

  if (Platform.isIOS) {
    final iosDeviceInfo = await deviceInfoPlugin.iosInfo;
    deviceInfo = DeviceInfo(
      id: await getDeviceId(),
      brand: 'Apple',
      model: iosDeviceInfo.model,
      productName: iosDeviceInfo.name,
      systemName: iosDeviceInfo.systemName,
      systemVersion: iosDeviceInfo.systemVersion,
    );
  } else if (Platform.isAndroid) {
    final androidDeviceInfo = await deviceInfoPlugin.androidInfo;
    deviceInfo = DeviceInfo(
      id: await getDeviceId(),
      brand: androidDeviceInfo.brand,
      model: androidDeviceInfo.model,
      productName: androidDeviceInfo.product,
      systemName: 'Android',
      systemVersion: androidDeviceInfo.version.release,
    );
  }
  return deviceInfo;
}
